package logic

import (
	"context"
	"seller_svc/sellerclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SellerAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSellerAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SellerAddLogic {
	return &SellerAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SellerAddLogic) SellerAdd(req *types.SellerAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.SellerRpc.SellerAdd(l.ctx, &sellerclient.SellerAddRequest{
		Name:   req.Name,
		Price:  float32(req.Price),
		Sales:  req.Sales,
		Coupon: req.Coupon,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "商品添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
